package cn.chinaflame.pagodas.utils;

import cn.chinaflame.pagodas.dto.PaMemberDto;
import cn.chinaflame.pagodas.service.PaMemberService;

import java.math.BigDecimal;

/**
 * @author pengcheng.zhao
 */
public class MemberBalance {

    /**
     * 更新会员消费余额
     *
     * @param paMemberService
     * @param memberId
     * @param payAmount
     * @param payDatetime
     */
    public static void memberBalance(PaMemberService paMemberService, String memberId, String payAmount, String payDatetime) {

        BigDecimal amount = new BigDecimal(payAmount);
        PaMemberDto oldmember = paMemberService.findOne(memberId);
        if (oldmember != null) {
            BigDecimal oldBalance = oldmember.getBalance() == null ? BigDecimal.ZERO : oldmember.getBalance();
            BigDecimal transAmt = amount;
            oldmember.setLastConsumeTime(payDatetime);
            oldmember.setBalance(oldBalance.add(transAmt));
            paMemberService.update1(oldmember);
        }
    }


}
